/******************************************************************************
 * Copyright (C) 2017 Chengdu Dlhd information industry co. LTD.
 * All Rights Reserved.
 * 本软件为成都顶联互动信息产业有限公司开发研制。未经本公司正式书面同意，其他任何个人、团体不得使用、复制、修改或发布本软件.
 *****************************************************************************/
package net.dgg.dggcloud.service.iboss.service.common;

import net.dgg.dggcloud.service.common.base.service.BaseService;
import net.dgg.dggcloud.service.iboss.constant.OverdueStateConstant;
import net.dgg.dggcloud.service.iboss.constant.ScStatusConstant;
import net.dgg.dggcloud.service.iboss.constant.ScWorkingConstant;
import net.dgg.dggcloud.service.iboss.dao.common.BacklogDao;
import net.dgg.dggcloud.service.iboss.dao.sc.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class BacklogService extends BaseService {
    @Autowired
    private BacklogDao backlogDao;
    @Autowired
    private WasteOrderDao wasteOrderDao;
    @Autowired
    private SuspendDao suspendDao;
    @Autowired
    protected ReturenedDao returenedDao;
    @Autowired
    private InProcessDao inProcessDao;
    @Autowired
    private AbolishDao abolishDao;


    public Integer getBacklogNum(Map paramMap) {
            Integer i = null;
            String code = null == paramMap.get("code") ? "" : paramMap.get("code").toString();
            if (code.equals(ScWorkingConstant.WORKING_WAITING_RECEIVE)) {//待接收
                paramMap.put("statusArr1", ScStatusConstant.RECEIVE_WAITING);//'SCORDER_STATUS01','SCORDER_STATUS11','SCORDER_STATUS12'
                paramMap.put("statusArr2", ScStatusConstant.SWITCH_WAITING);//'SCORDER_STATUS01','SCORDER_STATUS11','SCORDER_STATUS12'
                paramMap.put("statusArr3", ScStatusConstant.SWITCH_REFUSE);//'SCORDER_STATUS01','SCORDER_STATUS11','SCORDER_STATUS12'
                i = backlogDao.countWaitingReceive(paramMap);
                //待接收，转单待接收，转单驳回待接收

            } else if (code.equals(ScWorkingConstant.WORKING_ORDER_PROCESS)) {//办理中
                paramMap.put("status", ScStatusConstant.ORDER_PROCESS);
                i = backlogDao.countOrderProcess(paramMap);

            } else if (code.equals(ScWorkingConstant.WORKING_RETURENED_AUDIT)) {//退单审核中
                paramMap.put("status", ScStatusConstant.RETURENED_AUDIT);
                i = backlogDao.countReturenedAudit(paramMap);

            } else if (code.equals(ScWorkingConstant.WORKING_ABANDON_AUDIT)) {//废单审核中
                paramMap.put("status", ScStatusConstant.ABANDON_AUDIT);
                i = backlogDao.countAbandonAudit(paramMap);

            } else if (code.equals(ScWorkingConstant.WORKING_FOLLOW_TODAY)) {//今日待跟进
                paramMap.put("processStatus", ScStatusConstant.ORDER_PROCESS);// 今日待跟进
                i = backlogDao.countFollowToday(paramMap);

            } else if (code.equals(ScWorkingConstant.WORKING_NODE_DATEOUT)) {//节点超期
                paramMap.put("status", OverdueStateConstant.TIME_OUT);
                paramMap.put("processStatus", ScStatusConstant.ORDER_PROCESS);// 办理中
                i = backlogDao.countNodeDateout(paramMap);

            } else if (code.equals(ScWorkingConstant.WORKING_ORDER_DATEOUT)) {//订单超期
                paramMap.put("status", OverdueStateConstant.TIME_OUT);
                paramMap.put("processStatus", ScStatusConstant.ORDER_PROCESS);// 办理中
                i = backlogDao.countOrderDateout(paramMap);

            } else if (code.equals(ScWorkingConstant.WORKING_FOLLOW_DATEOUT)) {//超期跟进
                paramMap.put("processStatus", ScStatusConstant.ORDER_PROCESS);// 办理中
                i = backlogDao.countFollowDateout(paramMap);

            } else if (code.equals(ScWorkingConstant.WORKING_TOMORROW_REPAYMENT)) {//明日还款客户
                paramMap.put("tomorrowrepaymentType", "");// 查询自己以及自己部门的明日还款客户
                i = backlogDao.counTomorrowePayment(paramMap);

            } else if (code.equals(ScWorkingConstant.WORKING_TOMORROW_REPAYMENT_SINGLE)) {//明日还款客户--个人
                paramMap.put("tomorrowrepaymentType", "single");// 仅查询自己的明日还款客户
                i = backlogDao.counTomorrowePayment(paramMap);

            } else if (code.equals(ScWorkingConstant.WORKING_ORDER_ABANDON_SINGLE)) {//订单废单--个人
                paramMap.put("wasteType", "single");// 仅查询自己的订单废单客户
                i = wasteOrderDao.countAllWasteByMap(paramMap);

            } else if (code.equals(ScWorkingConstant.WORKING_ORDER_ORVERDUE_SINGLE)) {//订单超期--个人
                paramMap.put("overdueType", "single");// 仅查询自己的超期客户
                paramMap.put("proOverDue", OverdueStateConstant.TIME_OUT);
                paramMap.put("scstatus", ScStatusConstant.ORDER_PROCESS); //办理中
                i = inProcessDao.countInProcessByMap(paramMap);


            } else if (code.equals(ScWorkingConstant.WORKING_ORDER_SUSPENT_SINGLE)) {//订单暂缓--个人
                paramMap.put("suspendType", "single");// 仅查询自己的暂缓客户
                paramMap.put("status", ScStatusConstant.ORDERE_SUSPEND);
                i = suspendDao.countAllSuspendByMap(paramMap);

            } else if (code.equals(ScWorkingConstant.WORKING_ORDER_RETURENED_SINGLE)) {//订单退单--个人
                paramMap.put("returnedType", "single");// 仅查询自己的退单客户
                paramMap.put("status", ScStatusConstant.ORDER_RETURENED);
                i = returenedDao.countAllReutrnedByMap(paramMap);
            } else if (code.equals(ScWorkingConstant.WORKING_ORDER_ABANDON_TEAM)) {//订单废单--团队--crm
                paramMap.put("wasteType", "team");// 仅查询自己的订单废单客户
                i = wasteOrderDao.countAllWasteByMap(paramMap);

            } else if (code.equals(ScWorkingConstant.WORKING_ORDER_ORVERDUE_TEAM)) {//订单超期--团队--crm
                paramMap.put("overdueType", "team");// 仅查询自己的超期客户
                i = inProcessDao.countInProcessByMap(paramMap);
            } else if (code.equals(ScWorkingConstant.WORKING_ORDER_SUSPENT_TEAM)) {//订单暂缓--团队--crm
                paramMap.put("suspendType", "team");// 仅查询自己的暂缓客户
                paramMap.put("status", ScStatusConstant.ORDERE_SUSPEND);
                i = suspendDao.countAllSuspendByMap(paramMap);

            } else if (code.equals(ScWorkingConstant.WORKING_ORDER_RETURENED_TEAM)) {//订单退单--团队--crm
                paramMap.put("returnedType", "team");// 仅查询自己的退单客户
                paramMap.put("status", ScStatusConstant.ORDER_RETURENED);
                i = returenedDao.countAllReutrnedByMap(paramMap);
            } else if (code.equals(ScWorkingConstant.WORKING_ABANDON_AUDIT_SUPERIOR)) {//上级的废单待审核--crm
                paramMap.put("userId", paramMap.get("pageUserId"));//当前登录人是审核人
                paramMap.put("status", ScStatusConstant.ABANDON_AUDIT);//废单待审核状态
                // paramMap.put("pageUserId","");//只查看自己审核的
                i = abolishDao.countAbolishByMap(paramMap);

            } else if (code.equals(ScWorkingConstant.WORKING_RETURENED_AUDIT_SUPERIOR)) {//上级的退单待审核--crm
                paramMap.put("userId", paramMap.get("pageUserId"));//当前登录人是审核人
                paramMap.put("status", ScStatusConstant.RETURENED_AUDIT);//退单待审核状态
                //paramMap.put("pageUserId","");//只查看自己审核的
                i = abolishDao.countAbolishByMap(paramMap);

            }
            return i;
        }

}
